#include"MyPlayer.h"
void my_audio_callback(void *userdata, Uint8 *stream, int len){   
    DATAINFO*pos=GetAudioPacket();
    if(pos){
      int reallen=pos->length>len?len:pos->length;
      SDL_memset(stream, 0, len); 
      SDL_MixAudio(stream,pos->data,reallen,SDL_MIX_MAXVOLUME); 
      free(pos->data);
      free(pos);
    }
}


void InitAudioThread(){
    SDL_AudioSpec desired;
//  desired.freq=44100;
//  desired.freq=48000;
    desired.format=AUDIO_S16;
    desired.channels=2;
////AAC:1024  MP3:1152     
//  desired.samples=1024;
    desired.freq=sample_rate;
    desired.samples=samples;
    desired.callback=my_audio_callback;
    desired.userdata=NULL;
    if(SDL_OpenAudio(&desired, NULL) < 0 ){
       fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
       exit(-1);
    }
    bAudioThreadRunning=1;
    printf("Open Audio OK\n");
}